/*
 ============================================================================
 Name        : insertion_sort.c
 Author      : Yineng Chen
 Version     : 1.0
 Time        : 2011-10-03
 Description : Basic insertion sort algorithm
 ============================================================================
 */

#include <stdio.h>

int a[10]={6,35,7,9,1,2,7,43,8,3};

void insertion_sort(int data[],int length)
{
    int i=0,j=0;
    int cur=0;

    for(i=1;i<length;++i)
    {
        cur=data[i];
        for(j=i-1;(j>=0)&&(data[j]>cur);--j)
        {
            data[j+1]=data[j];
        }
        data[j+1]=cur;
    }
}

int main()
{
    printf("insetion_sort\n");
    int i=0;

    insertion_sort(a,10);

    for(i=0;i<10;++i)
    {
        printf("%d ",a[i]);
    }
    printf("\n");

    return 0;
}
